﻿Imports Co9320.Nicevote.ViewModel
Imports Co9320.Control

Class Application

    ' Startup、Exit、DispatcherUnhandledException などのアプリケーション レベルのイベントは、
    ' このファイルで処理できます。

    Private WithEvents ViewModel As MainViewModel
    Private WithEvents ScreenWindow As ScreenWindow
    Private WithEvents ConsoleWindow As ConsoleWindow


    Protected Overrides Sub OnStartup(ByVal e As StartupEventArgs)
        MyBase.OnStartup(e)
        


        ViewModel = New MainViewModel

        ScreenWindow = New ScreenWindow
        ConsoleWindow = New ConsoleWindow

        ScreenWindow.DataContext = ViewModel
        ConsoleWindow.DataContext = ViewModel


        ScreenWindow.Show()
        ConsoleWindow.Show()

    End Sub

    Private Sub ViewModel_RequestAreaSelection(ByVal sender As Object, ByVal e As System.EventArgs) Handles ViewModel.RequestAreaSelection
        Dim window = New SelectWindow With { _
            .Left = ScreenWindow.Left, _
            .Top = ScreenWindow.Top, _
            .Width = ScreenWindow.ActualWidth, _
            .Height = ScreenWindow.ActualHeight}

        If window.ShowDialog() Then
            ScreenWindow.Left = window.Rectangle.X
            ScreenWindow.Top = window.Rectangle.Y
            ScreenWindow.Width = window.Rectangle.Width
            ScreenWindow.Height = window.Rectangle.Height
        End If

    End Sub

    Private Sub ConsoleWindow_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ConsoleWindow.Closed
        If ScreenWindow IsNot Nothing Then
            ScreenWindow.Close()
        End If
        ConsoleWindow = Nothing
    End Sub

    Private Sub ScreenWindow_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles ScreenWindow.Closed
        If ConsoleWindow IsNot Nothing Then
            ConsoleWindow.Close()
        End If
        ScreenWindow = Nothing
    End Sub

    Private Sub ViewModel_RequestFontSelection(ByVal sender As Object, ByVal e As System.EventArgs) Handles ViewModel.RequestFontSelection

        Dim dialog = New FontDialogWindow
        dialog.SelectedFontFamily = ScreenWindow.FontFamily
        dialog.SelectedFontSize = ScreenWindow.FontSize

        If dialog.ShowDialog Then
            ScreenWindow.FontFamily = dialog.SelectedFontFamily
            ScreenWindow.FontSize = dialog.SelectedFontSize
        End If


    End Sub
End Class
